package com.mebs.edi.model.edi.e211;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.mebs.edi.model.dom.DomAttribute;
import com.mebs.edi.model.dom.DomChildren;
import com.mebs.edi.model.dom.DomEntity;
import com.mebs.model.Address;

/**
 * 
 * NN subsection of ST section in a 211 EDI file 
 * 
 * @author nit
 *
 */
@Entity()
@Table(name = "edi_211_nn")
@DomEntity(name = "N", discriminatorAttribute = "N101")
public class Edi211Nn {
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "Id")
	private Long id;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name="nn_id")
	@DomChildren
	private List<Edi211Gn> gn;
	
	@Column(nullable = true, length = 3)
	@DomAttribute
	private String n101; 	// Entity Identifier Code
	
	@Column(nullable = true, length = 60)
	@DomAttribute
	private String n102; 	// Name
	
	@Column(nullable = true, length = 55)
	@DomAttribute
	private String n301; 	// Address Info
	
	@Column(nullable = true, length = 55)
	@DomAttribute
	private String n302; 	// Address Info
	
	@Column(nullable = true, length = 30)
	@DomAttribute
	private String n401;	// City Name
	
	@Column(nullable = true, length = 30)
	@DomAttribute
	private String n402;	// State
	
	@Column(nullable = true, length = 15)
	@DomAttribute
	private String n403;	// Postal Code/ Zip Code
	
	@Column(nullable = true, length = 3)
	@DomAttribute
	private String n404;	// Country

	@ManyToOne(cascade = CascadeType.PERSIST, optional = false)
    @JoinColumn(name = "address_id")
	private Address address;
	
	public Edi211Nn() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getN101() {
		return n101;
	}

	public void setN101(String n101) {
		this.n101 = n101;
	}

	public String getN102() {
		return n102;
	}

	public void setN102(String n102) {
		this.n102 = n102;
	}

	public String getN301() {
		return n301;
	}

	public void setN301(String n301) {
		this.n301 = n301;
	}

	public String getN302() {
		return n302;
	}

	public void setN302(String n302) {
		this.n302 = n302;
	}

	public String getN401() {
		return n401;
	}

	public void setN401(String n401) {
		this.n401 = n401;
	}

	public String getN402() {
		return n402;
	}

	public void setN402(String n402) {
		this.n402 = n402;
	}

	public String getN403() {
		return n403;
	}

	public void setN403(String n403) {
		this.n403 = n403;
	}

	public String getN404() {
		return n404;
	}

	public void setN404(String n404) {
		this.n404 = n404;
	}

	public List<Edi211Gn> getGn() {
		return gn;
	}

	public void setGn(List<Edi211Gn> gn) {
		this.gn = gn;
	}
	
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	@Override
	public String toString() {
		return "Edi211Nn [id=" + id + ", gn=" + gn + ", n101=" + n101 + ", n102=" + n102 + ", n301=" + n301
				+ ", n302=" + n302 + ", n401=" + n401 + ", n402=" + n402 + ", n403=" + n403 + ", n405="
				+ n404 + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((gn == null) ? 0 : gn.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((n101 == null) ? 0 : n101.hashCode());
		result = prime * result + ((n102 == null) ? 0 : n102.hashCode());
		result = prime * result + ((n301 == null) ? 0 : n301.hashCode());
		result = prime * result + ((n302 == null) ? 0 : n302.hashCode());
		result = prime * result + ((n401 == null) ? 0 : n401.hashCode());
		result = prime * result + ((n402 == null) ? 0 : n402.hashCode());
		result = prime * result + ((n403 == null) ? 0 : n403.hashCode());
		result = prime * result + ((n404 == null) ? 0 : n404.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Edi211Nn other = (Edi211Nn) obj;
		if (gn == null) {
			if (other.gn != null)
				return false;
		} else if (!gn.equals(other.gn))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (n101 == null) {
			if (other.n101 != null)
				return false;
		} else if (!n101.equals(other.n101))
			return false;
		if (n102 == null) {
			if (other.n102 != null)
				return false;
		} else if (!n102.equals(other.n102))
			return false;
		if (n301 == null) {
			if (other.n301 != null)
				return false;
		} else if (!n301.equals(other.n301))
			return false;
		if (n302 == null) {
			if (other.n302 != null)
				return false;
		} else if (!n302.equals(other.n302))
			return false;
		if (n401 == null) {
			if (other.n401 != null)
				return false;
		} else if (!n401.equals(other.n401))
			return false;
		if (n402 == null) {
			if (other.n402 != null)
				return false;
		} else if (!n402.equals(other.n402))
			return false;
		if (n403 == null) {
			if (other.n403 != null)
				return false;
		} else if (!n403.equals(other.n403))
			return false;
		if (n404 == null) {
			if (other.n404 != null)
				return false;
		} else if (!n404.equals(other.n404))
			return false;
		return true;
	}
}
